package com.xszx.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.xszx.service.SystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.xszx.bean.Attention;

@Controller
@CrossOrigin
public class SystemController {

    @Autowired
    SystemService systemService;

    @RequestMapping("/getAttention")
    @ResponseBody
    public List<Attention> getAttention() {
        List<Attention> list = systemService.selectAttention();
        return list;
    }

    @RequestMapping("/getAllAttention")
    @ResponseBody
    public Map<String, Object> getAllAttention() {
        List<Attention> list = systemService.selectAllAttention();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", "0");
        map.put("data", list);
        map.put("msg", "");
        map.put("count", list.size());
        return map;
    }


    @RequestMapping("/searchAttention")
    @ResponseBody
    public Map<String, Object> searchAttention(@RequestParam String keyWord) {
        List<Attention> list = systemService.selectAttentionByKey(keyWord);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", "0");
        map.put("data", list);
        map.put("msg", "");
        map.put("count", list.size());
        return map;
    }

    @RequestMapping("/delAttention")
    @ResponseBody
    public boolean delAttention(@RequestParam int id) {
        int i = systemService.deleteAttention(id);
        if (i > 0) {
            return true;
        } else {
            return false;
        }
    }

    @RequestMapping("/addAttention")
    @ResponseBody
    public boolean addAttention(@RequestBody Attention attention) {
        int i = systemService.addAttention(attention);
        if (i > 0) {
            return true;
        } else {
            return false;
        }
    }

    @RequestMapping("/editAttention")
    @ResponseBody
    public boolean editAttention(@RequestParam int id) {
        int i = systemService.updateAttention(id);
        if (i > 0) {
            return true;
        } else {
            return false;
        }
    }
}
